<template>
	<view class="container">
		<view class="null"></view>
		<view class="staff-list">
			<view class="staff-item" v-for="(staff, index) in staffData" :key="index" @tap="editUser(staff,2)">
				<view class="staff-info">
					<uni-icons type="person-filled" size="30"></uni-icons>
					<view style="margin-left: 30rpx;">
						<view class="staff-name">{{ staff.username }}</view>
						<view class="staff-phone">{{ staff.mobile }}</view>
					</view>
				</view>
				<view class="swipe-handle">
					<view class="delete-btn" @click.stop="deleteStaff(staff.id)">
						<uni-icons type="trash-filled" size="24"></uni-icons>
					</view>
				</view>
			</view>
			<view class="empty" v-if="isEmpty">
				<image src="/static/empty-icon.png" mode="widthFix"></image>
				<text>暂无数据，如有问题，请联系客服</text>
			</view>
		</view>
		<button type="primary" class="add-btn" @click="addStaff(1,store_id)">
			<uni-icons type="add" size="24"></uni-icons>
			新增员工
		</button>
	</view>
</template>

<script>
	import {
		storeuserLists,
		deleteStoreuser
	} from "@/api/userApi/user.js"
	export default {
		data() {
			return {
				staffData: [],
				startX: 0,
				store_id: '',
				isEmpty:false
			};
		},
		methods: {
			deleteStaff(id) {
				deleteStoreuser({
					id: id
				}).then(res => {
					if (res.code == 200) {
						uni.showToast({
							icon: "none",
							title: "删除成功"
						})
						setTimeout(() => {
							this.getStoreuserLists()
						}, 1000)
					}
				})
			},
			editUser(val, type) {
				uni.navigateTo({
					url: `/pagesUser/editAndAddUser/editAndAddUser?val=${encodeURIComponent(JSON.stringify(val))}&type=${type}`
				});
			},
			addStaff(type,store_id) {
				uni.navigateTo({
					url: `/pagesUser/editAndAddUser/editAndAddUser?type=${type}&store_id=${store_id}`
				})
			},
			getStoreuserLists() {
				storeuserLists({
					store_id: this.store_id
				}).then(res => {
					if (res.code == 200) {
						if(res.data.list.length == 0){
							this.isEmpty = true
						}else{
							this.isEmpty = false
						}
						this.staffData = res.data.list
					}
				})
			}
		},
		onLoad(option) {
			this.store_id = option.id
		},
		onShow() {
			this.getStoreuserLists()
		}
	};
</script>

<style lang="scss">
	.container {
		background: #f5f5f5;
		height: 100vh;

		.null {
			width: 100%;
			height: 30rpx;
		}

		.staff-list {
			.staff-item {
				display: flex;
				justify-content: space-between;
				align-items: center;
				background-color: #fff;
				border-radius: 10rpx;
				padding: 30rpx;
				margin-bottom: 20rpx;
				box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
				position: relative;
				transition: transform 0.3s ease;

				.staff-info {
					display: flex;
					align-items: center;

					.staff-name {
						font-size: 28rpx;
						font-weight: bold;
						margin-bottom: 5rpx;
					}

					.staff-phone {
						font-size: 24rpx;
						color: #666;
					}
				}

				.swipe-handle {}
			}

			.empty {
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				position: absolute;
				top: 50%;
				left: 50%;
				transform: translate(-50%, -50%);

				image {
					width: 200rpx;
					margin-bottom: 20rpx;
				}

				text {
					font-size: 24rpx;
				}
			}
		}

		.add-btn {
			position: fixed;
			bottom: 20rpx;
			left: 50%;
			transform: translateX(-50%);
			width: 600rpx;
			height: 80rpx;
			border-radius: 40rpx;
			font-size: 28rpx;
			color: #fff;
			background-color: #3385FF;
			display: flex;
			align-items: center;
			justify-content: center;

			uni-icons {
				margin-right: 10rpx;
			}
		}
	}
</style>